import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class JpanelDemo extends JPanel {

    public static BufferedImage hero;
    public static BufferedImage bigplane;
    public static BufferedImage bg;
    public static BufferedImage airplane;
    public static BufferedImage bee;

    static {
        try {
            bg = ImageIO.read(JpanelDemo.class.getResourceAsStream("pic\\background.png"));
            hero = ImageIO.read(JpanelDemo.class.getResourceAsStream("pic\\hero0.png"));
            bigplane = ImageIO.read(JpanelDemo.class.getResourceAsStream("pic\\bigplane.png"));
            airplane = ImageIO.read(JpanelDemo.class.getResourceAsStream("pic\\airplane.png"));
            bee = ImageIO.read(JpanelDemo.class.getResourceAsStream("pic\\bee.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    hero h = new hero();
    bigplane b = new bigplane();
    airplane a = new airplane();
    bee be = new bee();

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(bg,0, 0, null);
        g.drawImage(h.getPic(), h.getX(), h.getY(), this);
        g.drawImage(b.getPic(), b.getX(), b.getY(), this);
        g.drawImage(a.getPic(), a.getX(), a.getY(), this);
        g.drawImage(be.getPic(), be.getX(), be.getY(), this);
    }

    public static void main(String[] args) {
        JFrame jframe = new JFrame("飞机大战");
        jframe.setSize(400, 600);
        JPanel myPanel = new JpanelDemo();
        jframe.add(myPanel);
        jframe.setDefaultCloseOperation(3);
        jframe.setVisible(true);
        bigplane bigplane = new bigplane();
        hero hero = new hero();
        airplane airplane = new airplane();
        bee bee = new bee();
    }
}
